package com.example.litterpainterdemo.draw.view

import android.app.Application
import android.graphics.Color
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.example.litterpainterdemo.draw.color.ColorModel
import com.example.litterpainterdemo.utils.ColorUtil
import com.example.litterpainterdemo.utils.dp2px

class DrawViewModel(application: Application):AndroidViewModel(application) {

    //监听工具
    var toolType = MutableLiveData(ToolType.None)
    //监听颜色
    var _color = MutableLiveData(Color.WHITE)
    //监听颜色模型
    var colorModels = MutableLiveData(emptyList<ColorModel>())
    //线条粗细
    var mLineWidth = MutableLiveData(application.dp2px(10))


    init {
        loadColorModels(100)
    }

    //改变数据
    fun setToolType(type: ToolType){
        toolType.postValue(type)
    }

    fun setColor(color:Int){
        _color.postValue(color)
    }

    fun setLineSize(size:Int){
        mLineWidth.postValue(getApplication<Application>().dp2px(size))
    }

    fun loadColorModels(count:Int){
        val colors = arrayListOf<ColorModel>()
        ColorUtil.getColors(count).forEach {
            colors.add(ColorModel(it))
        }

        colorModels.postValue(colors)
    }


}